package com.cn.goodsadmin.common.observes;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by fly on 17/5/5.
 */
public class TheadPool {

    /**
     * 统一管理发放奖励的线程池
     */
    public static ThreadPoolExecutor sendGiftThreadPoolExecutor = new ThreadPoolExecutor
            (100,
                    1000,
                    0L,
                    TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<Runnable>(200));
    /**
     * 统一管理消息层线程池
     */
    public static ThreadPoolExecutor ManagerMessageThreadPoolExecutor = new ThreadPoolExecutor
            (1,
                    1,
                    0L,
                    TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<Runnable>(200));


    /**
     * 统一监听者工作线程池线程池
     */
    public static ThreadPoolExecutor messageObserverWorkhreadPoolExecutor = new ThreadPoolExecutor
            (100,
                    1000,
                    0L,
                    TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<Runnable>(200));

    public static void destoryThreadPool() {
        if (!ManagerMessageThreadPoolExecutor.isShutdown()) {
            ManagerMessageThreadPoolExecutor.shutdown();
            ManagerMessageThreadPoolExecutor = null;
        }
        if (!sendGiftThreadPoolExecutor.isShutdown()) {
            sendGiftThreadPoolExecutor.shutdown();
            sendGiftThreadPoolExecutor = null;
        }
        if (!messageObserverWorkhreadPoolExecutor.isShutdown()) {
            messageObserverWorkhreadPoolExecutor.shutdown();
            messageObserverWorkhreadPoolExecutor = null;
        }
    }

}
